﻿using ITSM.Model;
using ITSM.Model.Entity;
using ITSM.Model.Model;
using Microsoft.Extensions.Logging;
using Quartz;
using Quartz.Logging;
using QuartzNetJob;
using SqlSugar;

namespace ITSM.Service.JobWork
{
    public class JobSendMessage : BaseDB, ScheduledTaskBase
    {
        private readonly IWxMessage _wxMessage;
        public JobSendMessage(IWxMessage wxMessage)
        {
            _wxMessage = wxMessage;
        }

        public async Task RunAsync(IJobExecutionContext context)
        {
            try
            {
                if (DateTime.Now.TimeOfDay < Convert.ToDateTime("2022-1-1 8:00").TimeOfDay || DateTime.Now.TimeOfDay > Convert.ToDateTime("2022-1-1 20:00").TimeOfDay || DateTime.Now.DayOfWeek == DayOfWeek.Sunday || DateTime.Now.DayOfWeek == DayOfWeek.Saturday)
                {
                    return;
                }

                M_Template? template = context.Trigger.JobDataMap.Get("Data") as M_Template;
                if (template == null)
                {
                    return;
                }
                template.client_msg_id = DateTimeOffset.Now.ToFileTime().ToString();
                template.data.first.value = "接单超时提醒！";
                template.data.remark.value = "该订单已超时！请尽快接单！";
                
                await _wxMessage.SendMessage(template);

            }
            catch (Exception)
            {

            }

        }
    }
}
